<?	
	require_once('functions.php');
	
	use_db_wordpress();

	$query = mysql_query("SELECT * FROM `$wp_comments`");

	if(!$query) {
		echo "<p>There are no comments.</p>";
	} else {
		while($row = mysql_fetch_array($query)) {

			$post_id = "";
			$old_post_id = "";
			$parent_id = "";
			$date = "";
			$content = "";
			$author_id = "";
			$author_name = "";
			$author_email = "";
			$author_url = "";
			$author_ip = "";
			$status = "";

			$id = $row['comment_ID'];
			$old_post_id = $row['comment_post_ID'];
			$parent_id = $row['comment_parent'];
			$date = strtotime($row['comment_date_gmt']);
			$content = addslashes($row['comment_content']);
			$author_name = addslashes($row['comment_author']);
			$author_email = addslashes($row['comment_author_email']);
			$author_url = addslashes($row['comment_author_url']);
			$author_ip = $row['comment_author_ip'];
			$status = $row['comment_approved'];
			if($status == "0") { $status = "moderation"; }
			if($status == "1") { $status = "approved"; }
			
			use_db_drizzo();
			
			$comment_author_lookup = mysql_query("SELECT * FROM `$drizzo_users` WHERE `nice_name`='$author_name' OR `username`='$author_name'");
			while($row = mysql_fetch_array($comment_author_lookup)) {
				$author_id = $row['ID'];
			}
			
			$comment_post_lookup = mysql_query("SELECT * FROM `$drizzo_posts` WHERE `import_id`='$old_post_id'");
			while($row = mysql_fetch_array($comment_post_lookup)) {
				$post_id = $row['ID'];
			}
			
			if($status != "spam") {
				$drizzo_insert = "INSERT INTO `$drizzo_comments` (`ID`, `post_id`, `parent_id`, `date`, `content`, `author_id`, `author_name`, `author_email`, `author_url`, `author_ip`, `status`, `edited_date`) VALUES ('', '$post_id', '$parent_id', '$date', '$content', '$author_id', '$author_name', '$author_email', '$author_url', '$author_ip', '$status', '" . time() . "')";
				mysql_query($drizzo_insert);
			}

			use_db_wordpress();
		}
	}
	
	echo "<p>" . mysql_num_rows($query) . " comments have been imported.</p>";
?>